﻿Imports System

Namespace System.Workflow.Runtime.Tracking
    <Serializable> _
    Public Class ActivityTrackingCondition
        Inherits TrackingCondition
        ' Methods
        Public Sub New()
        End Sub

        Public Sub New(ByVal member As String, ByVal value As String)
            If (member Is Nothing) Then
                Throw New ArgumentNullException("member")
            End If
            Me._property = member
            Me.SetValue(value)
        End Sub

        Friend Overrides Function Match(ByVal obj As Object) As Boolean
            If (obj Is Nothing) Then
                Throw New ArgumentNullException("obj")
            End If
            Dim property As Object = PropertyHelper.GetProperty(Me._property, obj)
            If (Me._op = ComparisonOperator.Equals) Then
                If ([property] Is Nothing) Then
                    Return (Nothing Is Me._val)
                End If
                Return (0 = String.Compare([property].ToString, Me._val, StringComparison.Ordinal))
            End If
            If ([property] Is Nothing) Then
                Return (Not Nothing Is Me._val)
            End If
            Return (0 <> String.Compare([property].ToString, Me._val, StringComparison.Ordinal))
        End Function

        Private Sub SetValue(ByVal value As String)
            Me._val = value
        End Sub


        ' Properties
        Public Overrides Property Member As String
            Get
                Return Me._property
            End Get
            Set(ByVal value As String)
                Me._property = value
            End Set
        End Property

        Public Overrides Property [Operator] As ComparisonOperator
            Get
                Return Me._op
            End Get
            Set(ByVal value As ComparisonOperator)
                Me._op = value
            End Set
        End Property

        Public Overrides Property Value As String
            Get
                Return Me._val
            End Get
            Set(ByVal value As String)
                Me.SetValue(value)
            End Set
        End Property


        ' Fields
        Private _op As ComparisonOperator
        Private _property As String
        Private _val As String
    End Class
End Namespace

